package cn.com.shadowless.xinning.view.fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import cn.com.shadowless.xinning.R;
import cn.com.shadowless.xinning.model.order.TravelOrderInfo;
import cn.com.shadowless.xinning.view.BaseFragment;

/**
 * The type Company child tab fragment.
 *
 * @author sHadowLess
 */
public class TravelChildTabFragment<T> extends BaseFragment {

    @BindView(R.id.main_tab)
    LinearLayout mainTab;

    private List<T> expenseListBeans;
    private String dataName;

    /**
     * Instantiates a new Company child tab fragment.
     */
    public TravelChildTabFragment(List<T> expenseListBeans, String dataName) {
        this.expenseListBeans = expenseListBeans;
        this.dataName = dataName;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_child_tab_layout;
    }

    @Override
    protected void initData() {
        switch (dataName) {
            case "出差费":
                List<TravelOrderInfo.DataBean.ExpenseListBean> expenseList = (List<TravelOrderInfo.DataBean.ExpenseListBean>) expenseListBeans;
                for (TravelOrderInfo.DataBean.ExpenseListBean expenseListBean : expenseList) {
                    View childView = LayoutInflater.from(mActivity).inflate(R.layout.fragment_travel_cost_child_tab_item, null, false);
                    LinearLayout childTab = childView.findViewById(R.id.travel_child_tab_item);
                    TextView travelChildTabTitle = childView.findViewById(R.id.cost_child_tab_title);
                    TextView travelChildTabCostProject = childView.findViewById(R.id.travel_child_tab_CostProject);
                    TextView travelChildTabCostStatus = childView.findViewById(R.id.travel_child_tab_CostStatus);
                    TextView travelChildTabDate = childView.findViewById(R.id.travel_child_tab_Date);
                    TextView travelChildTabApplyCost = childView.findViewById(R.id.travel_child_tab_applyCost);
                    String name = expenseListBean.getName();
                    String costContent = expenseListBean.getCostContent();
                    String expenseDateRange = expenseListBean.getExpenseDateRange();
                    String cost = getDecimal(expenseListBean.getCost().doubleValue());

                    travelChildTabTitle.setText(name);
                    travelChildTabCostProject.setText(name);
                    travelChildTabCostStatus.setText(costContent);
                    travelChildTabDate.setText(expenseDateRange);
                    travelChildTabApplyCost.setText(cost);
                    mainTab.addView(childTab);
                }
                break;
            case "交际费":
                List<TravelOrderInfo.DataBean.ComListBean> comList = (List<TravelOrderInfo.DataBean.ComListBean>) expenseListBeans;
                for (TravelOrderInfo.DataBean.ComListBean comListBean : comList) {
                    View childView = LayoutInflater.from(mActivity).inflate(R.layout.fragment_travel_expenses_child_tab_item, null, false);
                    LinearLayout childTab = childView.findViewById(R.id.expenses_child_tab_item);
                    TextView expensesChildTabTitle = childView.findViewById(R.id.expenses_child_tab_title);
                    TextView expensesChildTabDate = childView.findViewById(R.id.expenses_child_tab_date);
                    TextView expensesChildTabExpensesType = childView.findViewById(R.id.expenses_child_tab_expensesType);
                    TextView expensesChildTabWay = childView.findViewById(R.id.expenses_child_tab_way);
                    TextView expensesChildTabStatus = childView.findViewById(R.id.expenses_child_tab_status);
                    TextView expensesChildTabLocal = childView.findViewById(R.id.expenses_child_tab_local);
                    TextView expensesChildTabCustomName = childView.findViewById(R.id.expenses_child_tab_CustomName);
                    TextView expensesChildTabCustomPosition = childView.findViewById(R.id.expenses_child_tab_CustomPosition);
                    TextView expensesChildTabCustomLevel = childView.findViewById(R.id.expenses_child_tab_CustomLevel);
                    TextView expensesChildTabDuty = childView.findViewById(R.id.expenses_child_tab_duty);
                    TextView expensesChildTabJoinPeople = childView.findViewById(R.id.expenses_child_tab_joinPeople);
                    TextView expensesChildTabApplyCost = childView.findViewById(R.id.expenses_child_tab_applyCost);

                    String communicationDateStr = comListBean.getCommunicationDateStr();
                    String typeName = comListBean.getTypeName();
                    String wayName = comListBean.getWayName();
                    String communicationContent = comListBean.getCommunicationContent();
                    String address = comListBean.getAddress();
                    String name = comListBean.getName();
                    String duty = comListBean.getDuty();
                    String customerLevelStr = comListBean.getCustomerLevelStr();
                    String dutyRange = comListBean.getDutyRange();
                    String attendPeople = comListBean.getAttendPeople();
                    String cost = getDecimal(comListBean.getCost().doubleValue());

                    expensesChildTabTitle.setText(dataName);
                    expensesChildTabDate.setText(communicationDateStr);
                    expensesChildTabExpensesType.setText(typeName);
                    expensesChildTabWay.setText(wayName);
                    expensesChildTabStatus.setText(communicationContent);
                    expensesChildTabLocal.setText(address);
                    expensesChildTabCustomName.setText(name);
                    expensesChildTabCustomPosition.setText(duty);
                    expensesChildTabCustomLevel.setText(customerLevelStr);
                    expensesChildTabDuty.setText(dutyRange);
                    expensesChildTabJoinPeople.setText(attendPeople);
                    expensesChildTabApplyCost.setText(cost);
                    mainTab.addView(childTab);
                }
                break;
            default:
                break;
        }
    }

    @Override
    protected void initView() {

    }
}
